let dsf = {
  getToken: () => dsf.getcookie("token"),
  //页面滚动到顶部
  scrollTop: function () {
    document.body.scrollTop = document.documentElement.scrollTop = 0;
  },

  setcookie: function (key, value, time = 1) {
    const d = new Date();
    d.setTime(d.getTime() + 3600 * 1000 * 24 * time);
    // d.setTime(d.getTime() + 5000);
    time = d.toUTCString();
    document.cookie = `${key}=${value};expires=${time}`;
  },
  getcookie: function (key) {
    let cookieArr = document.cookie.split(";");
    for (let i = 0; i < cookieArr.length; i++) {
      let tmpArr = cookieArr[i].split("=");
      let tmpKey = tmpArr[0].replace(/\s/g, "");
      if (tmpKey == key) {
        return tmpArr[1];
      }
    }
    return "";
  },
  removecookie: function (key) {
    setcookie(key, 1, -1);
  },
  clearCookie: function () {
    let keys = document.cookie.match(/[^ =;]+(?=\=)/g);
    if (keys) {
      for (let i = keys.length; i--; ) {
        document.cookie = keys[i] + "=0;path=/;expires=" + new Date(0).toUTCString();
      }
    }
  },
  // 是身份证号吗
  iscard: function (str) {
    let re = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/;
    if (!re.test(str)) {
      return false;
    }
    return true;
  },
  // 是邮箱吗
  isemail: function (str) {
    let re = /^(\w-*\.*)+@(\w-?)+(\.\w{2,})+$/;
    if (!re.test(str)) {
      return false;
    }
    return true;
  },
  // 是手机号吗
  isphone: function (str) {
    let re = /^1\d{10}$/;
    if (!re.test(str)) {
      return false;
    }
    return true;
  },
  // 返回现在的时间
  getTime: function (timeType) {
    let now = new Date();
    let year = now.getFullYear(),
      month = now.getMonth() + 1,
      date = now.getDate(),
      hour = now.getHours(),
      minute = now.getMinutes(),
      second = now.getSeconds();
    minute = dsf.checkTime(minute);
    month = dsf.checkTime(month);
    date = dsf.checkTime(date);
    hour = dsf.checkTime(hour);
    second = dsf.checkTime(second);
    return year + "-" + month + "-" + date + " " + hour + ":" + minute + ":" + second;
  },
  checkTime: function (i) {
    if (i < 10) {
      i = "0" + i;
    }
    return i;
  },
  //是否是车牌号码(包括新能源)
  isCarNumber: function (str) {
    let re =
      /^(([京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领][A-Z](([0-9]{5}[DF])|([DF]([A-HJ-NP-Z0-9])[0-9]{4})))|([京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领][A-Z][A-HJ-NP-Z0-9]{4}[A-HJ-NP-Z0-9挂学警港澳使领]))$/;
    if (!re.test(str)) {
      return false;
    }
    return true;
  },
};
dsf.url = {
  queryString: function (key) {
    var globalCache = {};
    if (!globalCache["url_queryString"]) {
      globalCache["url_queryString"] = {};
    }
    if (!globalCache["url_queryString"][key]) {
      var url = window.location.hash;
      var oRegex = new RegExp("[?&]" + key + "=([^&]+)", "i");
      var oMatch = oRegex.exec(url);
      if (oMatch && oMatch.length > 1) {
        var val = decodeURI(oMatch[1]);
        globalCache["url_queryString"][key] = val;
        return val;
      } else {
        return "";
      }
    }
    return globalCache["url_queryString"][key];
  },
};
window.dsf = dsf;
